package com.zj.demo.aop;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.zj.demo.entity.Result;

@ControllerAdvice(basePackages="com.zj.demo.ctrl")
@ResponseBody
public class GlobalExceptionHandler {

//	private static final Logger logger = LogManager.getLogger(GlobalExceptionHandler.class);
	
	@ExceptionHandler(value=RuntimeException.class)
	public String runtimeExceptionHandler(RuntimeException e) {
		Gson gson=new Gson();
		Result result=new Result();
		result.setCode(500);
		result.setMsg("服务器异常");
		System.out.println(e);
		String str=gson.toJson(result);
		return str;
	}
}
